public class MyCircularQueue {
    private int[] elem;
    private int front;//表示队列的头
    private int rear;//表示队列的尾


        public MyCircularQueue(int k) {
            //如果是以牺牲一个空间来作为判断是否满了的标准，这里可以多申请一个空间
            elem = new int[k+1];
        }

        //入队列
        public boolean enQueue(int value) {
            if(isFull()){
                return false;
            }
            elem[rear] = value;
            rear = (rear + 1) % elem.length;
            return true;
        }

        //出队列
        public boolean deQueue() {
            if(isEmpty()){
                return false;
            }
            front = (front + 1) % elem.length;
            return true;

        }

        public int Front() {
            if(isEmpty()){
                return -1;
            }
            return elem[front];
        }

        public int Rear() {
            if(isEmpty()){
                return -1;
            }
            return rear == 0 ? elem[elem.length - 1] :elem[rear - 1];

        }

        public boolean isEmpty() {
            return rear == front;

        }

        public boolean isFull() {
            return (rear + 1) % elem.length == front;
        }

}
